# Maintainer: Felix Yan <felixonmars@archlinux.org>
# Contributor: Harry Jeffery <harry|@|exec64|.|co|.|uk>
# Contributor: Alex Jordan <alexander3223098@gmail.com>

pkgname=zerotier-one
pkgver=1.10.6
pkgrel=2
pkgdesc='Creates virtual Ethernet networks of almost unlimited size.'
arch=('loong64' 'x86_64')
url='https://www.zerotier.com/'
license=('custom:BSL')
depends=('gcc-libs' 'libnatpmp' 'miniupnpc')
makedepends=('rust')
options=('!lto')
source=("$pkgname-$pkgver.tar.gz::https://github.com/zerotier/ZeroTierOne/archive/refs/tags/$pkgver.tar.gz"
        'sysusers.conf')
sha512sums=('e22982e0898d5db4748ca009480cc6ea07b13e1cf3dcb2c78fbba5036519c0d08afe8bdad20766669f52fef03679ff228414337e2478990fd5ba5d3dbece1972'
            '1fdcc2e2a888ac7a93985bb6c16ac818aa6b7a56ccdeedf3cbbd22158251f6119f841e41e79b5522f9d1c6b8a315525d178cc42197c5eef2c70498b7954541f0')

prepare() {
  cd ZeroTierOne-$pkgver

  sed \
    -e 's/sbin/bin/' \
    -e 's/LDFLAGS=/LDFLAGS?=/' \
    -e 's/RUSTFLAGS=/RUSTFLAGS?=/' \
    -e 's/cargo build $(RUSTFLAGS)/cargo build --release/' \
    -i make-linux.mk debian/zerotier-one.service
}

build() {
  cd ZeroTierOne-$pkgver

  make V=1
}

check() {
  cd ZeroTierOne-$pkgver

  make selftest
  ./zerotier-selftest
}

package() {
  cd ZeroTierOne-$pkgver

  make DESTDIR="$pkgdir" install
  install -D -m0644 debian/zerotier-one.service "$pkgdir"/usr/lib/systemd/system/zerotier-one.service

  install -D -m0644 "$srcdir"/sysusers.conf "$pkgdir"/usr/lib/sysusers.d/"$pkgname".conf
}
